package projectManagement;

import javax.swing.JPanel;
import javax.swing.WindowConstants;

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
import javax.swing.border.TitledBorder;

public class ProjectOptionGUI extends JPanel implements ActionListener{
	JButton btnCompleted;
	String stat;
	public ProjectOptionGUI(String projectStatus) {
		setPreferredSize(new Dimension(431, 197));
		setLayout(null);
		
		if(projectStatus.equalsIgnoreCase("COMPLETED")){
			stat = "ONGOING";
		}else{
			stat = "COMPLETED";
		}
		
		JPanel memberPanel = new JPanel();
		memberPanel.setBorder(new TitledBorder(null, "Member Option", TitledBorder.LEADING, TitledBorder.TOP, null, null));
		memberPanel.setBounds(10, 11, 200, 169);
		add(memberPanel);
		memberPanel.setLayout(null);
		
		JButton btnAddMember = new JButton("Add Member");
		btnAddMember.setBounds(40, 35, 113, 57);
		btnAddMember.putClientProperty("Quaqua.Button.style", "bevel");
		btnAddMember.addActionListener(this);
		memberPanel.add(btnAddMember);
		
		JButton btnDeleteMember = new JButton("Delete Member");
		btnDeleteMember.setBounds(40, 88, 113, 57);
		btnDeleteMember.putClientProperty("Quaqua.Button.style", "bevel");
		btnDeleteMember.addActionListener(this);
		memberPanel.add(btnDeleteMember);
		
		JPanel projectPanel = new JPanel();
		projectPanel.setBorder(new TitledBorder(null, "SET PROJECT STATUS", TitledBorder.LEADING, TitledBorder.TOP, null, null));
		projectPanel.setBounds(220, 11, 200, 169);
		add(projectPanel);
		projectPanel.setLayout(null);
		
		btnCompleted = new JButton(stat);
		btnCompleted.setBounds(46, 51, 112, 65);
		btnCompleted.putClientProperty("Quaqua.Button.style", "bevel");
		btnCompleted.addActionListener(this);
		projectPanel.add(btnCompleted);
		
		
		JFrame f = new JFrame();
		f.add(this);
		f.setVisible(true);
		f.setResizable(false);
		f.setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE);
		f.pack();
		f.setLocationRelativeTo(null);
	}

	@Override
	public void actionPerformed(ActionEvent btn) {
		String cmd = btn.getActionCommand();
		
		if(cmd.equalsIgnoreCase("Add Member")){
			new AddingMemberGUI(ClientGUI.getAllMembers());
		}
		
		if(cmd.equalsIgnoreCase("Delete Member")){
			new DeleteMemberPanel(ClientGUI.getCurrentMembers());		
		}
		
		if(cmd.equalsIgnoreCase("COMPLETED")){
			btnCompleted.setText("ONGOING");
			ClientGUI.setLocalProjectStatus("COMPLETED");
			ClientGUI.sendCompletedProject();
		}
		
		if(cmd.equalsIgnoreCase("ONGOING")){
			btnCompleted.setText("COMPLETED");
			ClientGUI.setLocalProjectStatus("ONGOING");
			ClientGUI.sendOngoingProject();
		}
		
	}
}
